<template>
  <div class="page">
    <div class="weui-cells consumelist">
      <template v-if="resultList.length">
      <a class="weui-cell weui-cell_access" v-for="(item,index) in resultList" :key="index" @click="goDetail(item)">
        <div class="weui-cell__bd">{{item.orderNo}}</div>
        <div class="weui-cell__hd c_date">{{item.serviceTime}}</div>
        <div class="weui-cell__ft">查看详细</div>
      </a>

      </template>
       <!-- 无数据 -->
       <div class="outData" v-if="!resultList.length">
         暂无更多数据
       </div>
    </div>
  </div>
</template>

<script>
 import * as appId from "@/utils/util"
  import {getTIme} from "@/utils/util"
export default {
  data () {
    return {
      // phone:JSON.parse(wx.getStorageSync('userInfo')).mobileNo,
      pageNo:1,
      pageSize:10,
      result:[],
      resultList:[],
	  phone:"",
	  userInfo:{},
    }
  },
  mounted(){
      wx.setNavigationBarTitle({
      title: "我的消耗"
    })
	   this.userInfo =wx.getStorageSync('userInfo')&&JSON.parse(wx.getStorageSync('userInfo'))
	  if(this.userInfo) {
	    this.phone=this.userInfo.mobileNo;
	    this.consumeOrderList()


	  }else{
	    wx.showToast({
	      title:'请先登录',
	      icon: 'none',
	      duration: 2000
	    })
	  }

  },
   onPullDownRefresh(){
     console.log('down')
      if(this.result.length){
     this.pageNo++;
    }

     this.consumeOrderList()

  },
  methods: {
    goDetail(item){
         let url=`/pages/consumedetail/main?id=${item.id}`;

        wx.navigateTo({ url })
    },
    consumeOrderList(){
      let that=this;
       this.$http.request({
                    method:"post",
                    url:"/v1.0/appletLogin/consumeOrderList",
                    body:{
                      "phone":that.phone,
                      "appid":appId.appId,
                      "pageNo":that.pageNo,
                      "pageSize":that.pageSize,
            }
          }).then((data)=>{
              if(data.code==0){
              that.result=data.result;
               if (that.pageNo > 1) {
              that.resultList.push(...data.result)
                console.log(that.resultList)
              }else{
                that.resultList=data.result;
              }
              this.resultList.forEach((a,i)=>{
                a.serviceTime=getTIme(a.serviceTime)
              })
               if(!data.length){
               wx.stopPullDownRefresh();
            //    wx.showToast({
            //   title: '暂无更多数据',
            //   icon: 'none',
            //   duration: 2000
            // })
            }

            }else{
               wx.showToast({
              title: `${data.message}`,
              icon: 'none',
              duration: 2000
            })
            }
          }).catch((err)=>{
             wx.showToast({
              title: "请求失败",
              icon: 'none',
              duration: 2000
            })
          })
    }
  },

  created () {
  }
}
</script>

<style scoped>
.outData{
  text-align: center;
  padding:0.5em;
}
.consumelist{
  font-size: 0.8em;
}
.c_date{
  color: #999;
  padding-right: 0.6em;
}
</style>
